package com.xxxx.yoyo.dao.impl;

import java.util.List;

import com.xxxx.yoyo.bean.Top;
import com.xxxx.yoyo.dao.ITopDao;
import com.xxxx.yoyo.util.DBUtils;

public class TopDaoImpl implements ITopDao {

	/**
	 * 根据宠物的id查询宠物所属的榜单
	 * @param goodsId 宠物的id
	 * @return 返回宠物所属榜单列表
	 */
	@Override
	public List<Top> selectTopListByGoodsId(int goodsId) {
		String sql = "SELECT * FROM top WHERE good_id = ?";
		List<Top> topList = DBUtils.query(sql, Top.class, goodsId);
		return topList;
	}

	/**
	 * 添加榜单信息
	 * @param top 榜单对象
	 * @return 添加成功返回1，失败返回0
	 */
	@Override
	public int insertTop(Top top) {
		String sql = "INSERT INTO top(type,good_id) VALUES (?, ?)";
		int row = DBUtils.update(sql, top.getType(), top.getGoodId());
		return row;
	}

	/**
	 * 删除榜单信息
	 * @param top 榜单对象
	 * @return 删除成功返回1，失败返回0
	 */
	@Override
	public int deleteTop(Top top) {
		String sql ="DELETE FROM top WHERE type = ? AND good_id = ?";
		int row = DBUtils.update(sql,top.getType(), top.getGoodId());
		return row;
	}

}
